package com.atguigu.boot.config;

import ch.qos.logback.core.db.DBHelper;
import com.atguigu.boot.bean.Car;
import com.atguigu.boot.bean.Pet;
import com.atguigu.boot.bean.User;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * @Configuration ://告诉SpringBoot这是一个配置类，相当于之前的bean.xml文件
 * @Bean: 给容器中添加组件，以方法名作为组件的id,返回类型是组件类型，返回的值就是在组件中的实例
 * @Import({User.class,DBHelper.class})
 */

@Import({User.class, DBHelper.class})
@Configuration
@ConditionalOnMissingBean(name = "tom")
@EnableConfigurationProperties(Car.class)
public class Myconfig {

    @Bean
    public User user01() {
        return new User("zhangsan", 10);
    }

    @Bean("tom1") //自定义组件名
    public Pet tomcatPet() {
        return new Pet("tomcat");
    }
}
